import 'package:flutter/material.dart';
import 'package:happy_elf_app/store/config.dart';
import 'package:happy_elf_app/store/home.dart';
import 'package:happy_elf_app/utils/globalKey.dart';
import 'package:happy_elf_app/views/Home/set/index.dart';
import 'package:happy_elf_app/views/Home/split/index.dart';
import 'package:happy_elf_app/views/Home/track/index.dart';
import 'package:happy_elf_app/views/Home/widgets/homeBar.dart';

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

final HomeDataProvider = Provider.of<HomeData>(
  Global.navigatorKey.currentContext!,
  listen: false,
);

class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  String target = ''; // 最终的目标

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    print('HomeDataProvider.activeTab${HomeDataProvider.activeTab}');
    return Consumer<HomeData>(builder: (context, homeData, child) {
      return Scaffold(
        backgroundColor: Colors.white,
        body: Column(children: [
          Expanded(
            child: HomeDataProvider.activeTab['value'] == 1
                ? TaggetSet(callback: () {
                    // 确认好目标了
                    HomeDataProvider.setTab({'title': '任务拆分', 'value': 2});
                    setState(() {});
                  })
                : HomeDataProvider.activeTab['value'] == 2
                    ? SplitDefalut(
                        callback: () {
                          HomeDataProvider.setTab(
                              {'title': '任务追踪', 'value': 3});
                          setState(() {});
                        },
                      )
                    : Track(
                        callback: () {
                          HomeDataProvider.setTab(
                              {'title': '目标设定', 'value': 1});
                        },
                      ),
          ),
          HomeBar()
        ]),
      );
    });
  }
}
